package com.jxk.test.service;

import org.springframework.scheduling.annotation.Async;
import org.springframework.scheduling.annotation.AsyncResult;
import org.springframework.stereotype.Service;

import java.util.concurrent.Future;
import java.util.concurrent.TimeUnit;

/**
 * @ClassName : AsyncService  //类名
 * @Description :   //描述
 * @Author : jxk  //作者
 * @Date: 2020-10-13 14:11  //时间
 */
@Service
public class AsyncService {
    @Async
    public Future<String> asyncTask(String name){
        Future<String> returnmsg;
        try {
            TimeUnit.SECONDS.sleep(1);
            System.out.println("线程名字"+Thread.currentThread().getName());

            returnmsg=new AsyncResult<String>("sucess");//没异常就返回这个
        } catch (InterruptedException e) {
            returnmsg=new AsyncResult<String>("异常为"+e.getMessage());
        }
        System.out.println("------------------oh yes");
        return returnmsg;
    }
}
